from tkinter import *
from sys import exit


# 定义一个类部件
class Hello(Frame):
    def __init__(self, parent=None):
        Frame.__init__(self, parent)
        self.pack()
        self.data = 42
        # 将组件附加到self
        self.make_widgets()

    def make_widgets(self):
        widget = Button(self, text="hello按钮", command=self.message)
        widget.pack(side=LEFT)

    def message(self):
        self.data += 1
        print("data的值发生了变化：", self.data)


# 拓展类部件
class HelloExtender(Hello):
    def make_widgets(self):
        Hello.make_widgets(self)
        # 在这里拓展方法
        Button(self, text="拓展类按钮", command=self.quit).pack(side=RIGHT)


HelloExtender().mainloop()
